﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace MiniFox.Platform.Models
{
    /// <summary>
    /// 
    /// </summary>
    [JsonObject]
    public class AuthorizeToken
    {
        DateTime? _creationTime;
        /// <summary>
        /// 
        /// </summary>
        public AuthorizeToken()
        {
        }
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("accessToken")]
        public virtual string AccessToken { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("refreshToken")]
        public virtual string RefreshToken { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("scope")]
        public virtual string Scope { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [JsonProperty("duration")]
        public virtual int Duration { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [JsonIgnore, XmlIgnore]
        public DateTime? CreationTime
        {
            get
            {
                if (_creationTime == null)
                    _creationTime = DateTime.Now;
                return _creationTime;
            }
            set { _creationTime = value; }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public bool AccessTokenExpired()
        {

            var creationTime = CreationTime.GetValueOrDefault();
            return DateTime.Now >= creationTime.AddSeconds(Duration);
        }
    }
}
